using CMS.Application.common.Interface;
using CMS.Application.Common.Interface;
using CMS.Application.RequestDto;
using CMS.Domain.Entity;
using Microsoft.AspNetCore.Mvc;
using SoftDemo.Api.Controllers;

namespace CMS.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UserManagementController : ControllerBase
    {
        private readonly IRepository<Users> _users;
        private readonly IRepository<Avatar> _avatar;

        // private readonly IFileUploadService _fileUploadService;//调用上传图片的接口

        public UserManagementController(IRepository<Users> users, IRepository<Avatar> avatar)
        {
            _users = users;
            _avatar = avatar;
            // _fileUploadService=fileUploadService;
        }

        [HttpPut("/img/{id}")]
        public async Task<dynamic> put(Guid id, UserManageDto userManageDto)
        {

            // //调用上传图片的方法
            // var uploadController = new UploadController(_fileUploadService);

            //根据id查找到当前的用户
            var userTable = await _users.GetByIdAsync(id);

            // // 上传头像图片拿到id
            //  var result = await uploadController.OnPostUploadAsync().Id;

            // await _avatar.AddAsync(avatarTable);
            //根据用户名查询到头像的id，根据新传入头像的id进行更新

            if (userTable != null)
            {
                userTable.UserName = userManageDto.UserName;
                userTable.AvatarId = userManageDto.AvatarId;
                await _users.UpdateAsync(userTable);
                return new
                {
                    code = "200",
                    data = "",
                    msg = "更新成功"
                };
            }else
            {
                 return new
                {
                    code = "400",
                    data = "",
                    msg = "更新失败"
                };
            }


        }


    }




}